<template>
	<view class="">
		<searchLink></searchLink>
		<!-- 主体内容 -->
		<view class="content">
			<!-- 左侧  -->
			<view class="left">
				<view class="item" :class="{active:activeindex === index}" @click="selectCat(index)" v-for="(item,index) in leftcategories"
				 :key="index">
					{{item.cat_name}}
				</view>
			</view>
			<!-- 右侧 -->
			<view class="right" v-if="leftcategories.length != 0">
				<image src="../../static/images/titleImage.png" mode=""></image>
				<!-- 二级分类 -->
				<view class="catw2" v-for="(cate2,index2) in leftcategories[activeindex].children" :key="index2">
					<view class="name">
						/<text>{{cate2.cat_name}}</text>/
					</view>
					<!-- 三级分类 -->
					<view class="cate3-wrapper">
						<!-- 点击跳转 -->
						<view @click="toSearchList(cate3.cat_name)" class="cate3" v-for="(cate3,index3) in cate2.children" :key="index3">
							<image :src="cate3.cat_icon" mode=""></image>
							<text>{{cate3.cat_name}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// import searchlink from '../../components/searchLink.vue' 
	import searchLink from '../../components/searchLink.vue'
	export default {
		components: {
			searchLink
		},
		data() {
			return {
				// 左侧商品分类
				leftcategories: [],
				activeindex: 0,
				// 三级商品分类数组
				cate3List: []

			}
		},
		onLoad() {
			this.getLeftCategories()
		},
		methods: {
			// 跳转到 搜索列表页
			toSearchList(cartName) {
				wx.navigateTo({
					url: '/pages/searchList/searchList?catName=' + cartName
				})
			},
			selectCat(index) {
				this.activeindex = index
			},
			// 获取左侧商品分类
			async getLeftCategories() {

				var data = await this.$request({
					url: '/v1/categories'
				})
				this.leftcategories = data
			}

		}
	}
</script>

<style lang="less">
	.content {
		display: flex;
		position: absolute;
		left: 0;
		right: 0;
		bottom: 0;
		top: 100rpx;

		.left {
			width: 198rpx;
			overflow: scroll;

			.item {
				height: 100rpx;
				line-height: 100rpx;
				box-sizing: border-box;
				border-bottom: 1px solid #eee;
				background-color: #f4f4f4;
				color: #333;
				text-align: center;

				&.active {
					position: relative;
					background-color: #fff;
					color: red;
					position: relative;

					// 伪类
					&::before {
						content: '';
						position: absolute;
						width: 8rpx;
						height: 60rpx;
						left: 0;
						top: 20rpx;
						background-color: red;
					}
				}
			}

		}

		.right {
			overflow: scroll;
			flex: 1;
			padding: 20rpx 16rpx 0;

			>image {
				width: 520rpx;
				height: 180rpx;
			}

			.catw2 {
				.name {
					height: 110rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					color: #e0e0e0;

					text {
						color: #333;
						margin: 0 30rpx;
					}
				}

				.cate3-wrapper {
					display: flex;
					flex-wrap: wrap;
					margin-bottom: 20rpx;

					.cate3 {
						width: 33.3%;
						display: flex;
						flex-direction: column;
						align-items: center;
						margin-bottom: 20rpx;

						image {
							width: 120rpx;
							height: 120rpx;
						}

						text {
							// font-size: 16rpx;
							// color: ;
						}
					}
				}
			}

		}

	}
</style>
